<template>
	<sl-page :isDisplay="false">
		<view class="tenant">
			<!-- 头部 -->
			<view class="tenant-head">
				<view class="head-content">
					<view class="content-profile">
						<view class="profile-headimg" v-if="store.image">
							<sl-image :value="store.image"></sl-image>
						</view>
						<view class="profile-avatar" v-else>
							<sl-image :value="avatar"></sl-image>
						</view>
					</view>
					<view class="flex py-1">
						<view class="content-name">
							{{store.name}}
						</view>
						<view class="flex flex-y-center">
							<uni-icons type="bottom" size="16" color="#fff"></uni-icons>
						</view>

					</view>
				</view>
			</view>
			<view class="tenant-account">
				<view class="flex flex-dir-column flex-y-center flex-basis-30" v-for="(item, index) in tenantAnalyse"
					:key="index">
					<Money :priceValue="item.count" :activeClass="['money-36']"></Money>
					<view class="py-1 f-tip f-24">{{ item.name }}</view>
				</view>
			</view>
			<!-- 会员卡 -->
			<view class="tenant-body">
				<!-- 星橘服务 -->
				<view class="body-data">
					<view class="data-head">
						<view class="f-w">门店管理</view>
					</view>
					<view class="data-menu">
						<view class="flex flex-column flex-y-center " @click="toTargetPage(item.url)"
							v-for="(item, index) in services" :key="index">
							<view class="iconfont" :class="item.icon"></view>
							<view class="py-1 f-tip f-24">{{ item.name }}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</sl-page>
</template>

<script>
	import StoreApi from '@/api/store/store.js';
	import Constants from '@/constants';
	import Money from '@/pages/components/money/money.vue';

	export default {
		name: 'distributionIndex',
		//
		mixins: [Constants],
		//
		components: {
			Money
		},
		//
		data() {
			return {
				//跳转路径
				// distributionUrl: 'xj_distribution/index/index',
				// tenantUrl: 'xj_tenant/store/index',
				//用户昵称
				nickname: '',
				//正在加载
				isLoading: true,
				//是否已登录
				isLogin: false,
				//分销用户
				store: {},
				user: {},
				//当前用户会员信息
				member: {},
				//订单
				orders: [],
				//星橘服务
				services: [],

				//订单相关
				todoCounts: {
					payment: 0,
					deliver: 0,
					received: 0,
					refund: 0
				},
				//账户分析
				tenantAnalyse: [],
			};
		},
		//
		computed: {

		},
		//
		onLoad() {
			this.initAccountMenu();
			this.initServiceMenu();
		},
		//
		onShow() {

			this.onRefreshPage();
		},
		//
		methods: {
			//初始化账户菜单
			initAccountMenu() {
				this.tenantAnalyse = [{
					id: '1',
					name: '今日订单',
					url: 'xj_user/collection/index',
					count: 12,
					value: 'productCount'
				}, {
					id: '2',
					name: '今日交易额',
					url: 'xj_user/follow/index',
					count: 456,
					value: 'tenantCount'
				}, {
					id: '3',
					name: '今日客单价',
					count: 100,
				}, {
					id: '4',
					name: '本月订单',
					count: 100,
				}, {
					id: '5',
					name: '本月交易额',
					count: 100,
				}, {
					id: '6',
					name: '本月客单价',
					count: 100,
				}];
			},
			//初始化数据看板菜单
			initServiceMenu() {
				this.services = [{
					id: '1',
					name: '店铺管理',
					icon: 'icon-dianpuguanli1',
					url: 'xj_tenant/index/update',
				}, {
					id: '2',
					name: '订单管理',
					icon: 'icon-dingdanguanli1',
					url: 'xj_tenant/order/index',
				}, {
					id: '3',
					name: '门店核销',
					icon: 'icon-mendianhexiao2',
					url: 'xj_tenant/verification/manual',
				}, {
					id: '4',
					name: '扫码核销',
					icon: 'icon-saomahexiao1',
					url: 'xj_tenant/verification/scan',
				}];
			},
			//
			onRefreshPage() {
				//判断是否已登录
				// this.isLogin = !!this.$store.getters.token;
				//获取页面数据
				// if (this.isLogin) {
				this.getPageData();
				// }
			},
			//获取页面数据
			getPageData: async function() {
				const app = this;
				app.isLoading = true;
				//获取业务数据
				Promise.all([app.getStores()])
					.then(result => {
						//
						// this.nickname = result[0].name;
						// 初始化订单操作数据
						// app.initOrderTabbar();
						// app.initFFC();
						// 执行回调函数
						// callback && callback(); 
					})
					.catch(err => console.log('【获取页面数据数据失败】:', err))
					.finally(() => {
						app.isLoading = false;
					});
			},
			//得到分销人
			getStores: async function() {
				let res = await StoreApi.query();
				console.log('res: -------------------', res);
				this.store = res.obj[0];
			},
			//跳转到我的相关
			toTargetPage(url) {
				// if (!this.isLogin) {
				// 	this.handleLogin();
				// } else {
				// const userId = this.$store.getters.user.id;
				this.$app.navTo(url, {
					storeId: this.store.id,
					tenantId: this.store.tenantId
				});
				// }
			},
		}
	};
</script>

<style lang="scss" scoped>
	.tenant {
		font-size: $uni-font-size-base;
		color: $uni-text-color-primary;

		.tenant-head {
			position: absolute;
			top: 0;
			left: 0;
			right: 0;
			height: 546rpx;
			background-image: url("@/xj_tenant/static/storeBackground.png");
			z-index: 1;

			.head-content {
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				margin-top: 124rpx;
				margin-left: 46rpx;
				margin-right: 46rpx;

				.content-profile {
					position: relative;
					width: 104rpx;
					height: 104rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					border-radius: 10%;
					overflow: hidden;
					border: 2rpx solid #CCCCCC;
					background-color: #FFFFFF;

					.profile-headimg {
						position: relative;
						width: 104rpx;
						height: 104rpx;
					}

					.profile-avatar {
						position: relative;
						width: 72rpx;
						height: 60rpx;
						opacity: 0.3;
					}
				}

				.content-name {
					color: #FFF;
					font-feature-settings: 'clig' off, 'liga' off;
					font-family: PingFang SC;
					font-size: 18px;
					font-style: normal;
					font-weight: 500;
					// line-height: 20px; 
				}

				.content-level {
					margin-top: 6rpx;
					position: relative;
					width: 60rpx;
					height: 50rpx;
				}
			}
		}

		.tenant-account {
			position: relative;
			margin-top: 428rpx;
			display: flex;
			justify-content: space-around;
			flex-wrap: wrap;
			height: 127px;
			margin-left: 32rpx;
			margin-right: 32rpx;
			padding: 40rpx 0rpx;
			border-radius: 4px;
			background: #FFF;
			box-shadow: 0px 2px 9px 0px rgba(0, 0, 0, 0.06);
			// border: 1px solid red;
			z-index: 30;
		}

		.tenant-body {
			position: relative;
			margin-top: -16px;
			display: flex;
			flex-direction: column;
			// height: 576px;
			flex-shrink: 0;
			border-radius: 20rpx;
			z-index: 20;
			background-color: $uni-bg-color-grey;
			// border: 1px solid yellow;


			.body-data {
				display: flex;
				flex-direction: column;
				margin-left: 32rpx;
				margin-right: 32rpx;
				height: 218rpx;
				background: #FFFFFF;
				box-shadow: 0rpx 4rpx 18rpx rgba(0, 0, 0, 0.06);
				border-radius: 8rpx;
				margin-top: 64rpx;

				.data-head {
					display: flex;
					justify-content: space-between;
					margin-top: 26rpx;
					margin-left: 32rpx;
					margin-right: 32rpx;
				}

				.data-menu {
					display: flex;
					justify-content: space-between;
					margin-left: 78rpx;
					margin-right: 78rpx;
					padding-top: 62rpx;
					font-size: 24rpx;
				}
			}
		}
	}
</style>